home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Human Interface Toolbox / GetDragHiliteColor / GetDragHilite.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.5 KB  |  145 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        GetDragHilite.c
  3.  
  4.     Contains:    This shows how to obtain the color that the Drag Manager uses to
  5.                 hilite regions when ShowDragHilite is called.  Check out GetDragHilite.c
  6.                 for the code.  
  7.  
  8.                 Please note this is only how it's done presently.  Since it is undocumented
  9.                 it can and will change in the future.
  10.  
  11.     Written by: Nitin Ganatra    
  12.  
  13.     Copyright:    Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
  14.     
  15.                 You may incorporate this Apple sample source code into your program(s) without
  16.                 restriction. This Apple sample source code has been provided "AS IS" and the
  17.                 responsibility for its operation is yours. You are not permitted to redistribute
  18.                 this Apple sample source code as "Apple sample source code" after having made
  19.                 changes. If you're going to re-distribute the source, we require that you make
  20.                 it clear in the source that the code was descended from Apple sample source
  21.                 code, but that you've made changes.
  22.  
  23.     Change History (most recent first):
  24.                 8/6/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  25.                 
  26.  
  27. */
  28. #include <Windows.h>
  29. #include <QuickDraw.h>
  30.  
  31. #define wTitleBarColor    4
  32. #define wTingeLight        11
  33. #define wTingeDark        12
  34.  
  35. unsigned short BlendValues(short lightValue, short darkValue);
  36. void SetupDragHiliteColor(WindowPtr targetWindow);
  37.  
  38.  
  39. /*-------------------------------------------------------------------------------------
  40.  
  41. BlendValues
  42.  
  43.     Blend two color values by 27%.  Be careful of overflow when multiplying
  44.     a negative number.  Output should be light + 27% of difference between light
  45.     and dark.
  46.  
  47. */
  48. unsigned short BlendValues(short lightValue, short darkValue)
  49. {
  50.     register short blender;
  51.  
  52.     blender = darkValue - lightValue;
  53.  
  54.     if ((unsigned long)lightValue > (unsigned long)darkValue)
  55.         blender = -blender;                        // flip if subtraction would overflow
  56.  
  57.     blender = (unsigned short)((unsigned short)blender * .27);
  58.                                                 // 27% percent multiply
  59.  
  60.     if ((unsigned long)lightValue > (unsigned long)darkValue)
  61.         blender = -blender;                        // flip it back if it was flipped the
  62.                                                 // first time.
  63.  
  64.     return ((unsigned short)(lightValue + blender));
  65. }
  66.  
  67.  
  68. /*-------------------------------------------------------------------------------------
  69.  
  70. SetupDragHiliteColor
  71.  
  72.     Set the fore color to the color used by the Drag Manager to hilite regions.
  73.     
  74. */
  75. void SetupDragHiliteColor(WindowPtr targetWindow)
  76. {
  77.     RGBColor windowRGB, lightRGB, darkRGB;
  78.     AuxWinHandle auxHandle;                        // the default AuxWindow data
  79.     CTabHandle winColorTable;                        // the window color table
  80.     short i, j;                                    // for our color table search
  81.  
  82.     windowRGB.red = 0x8000;                        // Default to 50% gray.
  83.     windowRGB.green = 0x8000;
  84.     windowRGB.blue = 0x8000;
  85.  
  86.     // If we're using a window which uses System 7's 3D colors
  87.     // then set the hilite color to a tinge for that window.
  88.  
  89.     GetAuxWin(targetWindow, &auxHandle);
  90.  
  91.     // do we have an aux window handle ?
  92.     if (auxHandle != nil) {
  93.         winColorTable = (**auxHandle).awCTable;
  94.  
  95.         // do we have a system 7 sized window color table?
  96.         if ((**winColorTable).ctSize > wTitleBarColor) {
  97.             
  98.             // yes, now search for the tinge color, start at the end
  99.             // because our tinge colors are usually last in the list.
  100.             for (i = (**winColorTable).ctSize; i > 0; i--) {
  101.                 if ((**winColorTable).ctTable[i].value == wTingeLight) {
  102.  
  103.                     // light tinge found, set the window color to it
  104.                     // in case we can't find the dark tinge.
  105.                     lightRGB = (**winColorTable).ctTable[i].rgb;
  106.  
  107.                     windowRGB.red = lightRGB.red;
  108.                     windowRGB.green = lightRGB.green;
  109.                     windowRGB.blue = lightRGB.blue;
  110.  
  111.                     // we now need the wTingeDark entry to perform a blend.
  112.                     // again, search from the end
  113.                     for (j = (**winColorTable).ctSize; j > 0; j--)
  114.                         if ((**winColorTable).ctTable[j].value == wTingeDark) {
  115.                             // dark tinge found.  now do the blend
  116.  
  117.                             darkRGB = (**winColorTable).ctTable[j].rgb;
  118.  
  119.                             windowRGB.red = BlendValues((short)lightRGB.red, (short)darkRGB.red);
  120.                             windowRGB.green = BlendValues((short)lightRGB.green, (short)darkRGB.green);
  121.                             windowRGB.blue = BlendValues((short)lightRGB.blue, (short)darkRGB.blue);
  122.  
  123.                             // if the Color control panel was set to "Black and White", it makes the
  124.                             // tinge colors black and black.  Use gray in this case
  125.  
  126.                             if ((windowRGB.red | windowRGB.green | windowRGB.blue) == 0) {
  127.                                 windowRGB.red = 0x8000;
  128.                                 windowRGB.green = 0x8000;
  129.                                 windowRGB.blue = 0x8000;
  130.                             }
  131.  
  132.                             j = 0;                // bail from inner loop
  133.                         }
  134.  
  135.                     i = 0;                        // bail from outer loop
  136.                 }
  137.             }
  138.         }
  139.     }
  140.  
  141.     RGBForeColor(&windowRGB);        // finally, set it
  142. }
  143.  
  144.  
  145.